package com.example.czy.annotation;

import com.example.czy.utils.DataMaskingSerialize;
import com.fasterxml.jackson.annotation.JacksonAnnotationsInside;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * 数据脱敏注解
 *
 * @author czy
 * @date 2023-09-01 18:01
 */
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@JacksonAnnotationsInside
@JsonSerialize(using = DataMaskingSerialize.class)
public @interface DataMasking {

    /**
     * 数据脱敏类型
     */
    Type type() default Type.CUSTOM;

    /**
     * 开始位置
     */
    int start() default 0;

    /**
     * 结束位置 不包含
     */
    int end() default 0;

    enum Type {
        USER_ID,
        CHINESE_NAME,
        ID_CARD,
        FIXED_PHONE,
        MOBILE_PHONE,
        ADDRESS,
        EMAIL,
        PASSWORD,
        CAR_LICENSE,
        BANK_CARD,
        IPV4,
        IPV6,
        FIRST_MASK,
        CLEAR_TO_NULL,
        CLEAR_TO_EMPTY,
        CUSTOM;
    }
}

